//
//  BGZNXDetailViewController.m
//  bigMall
//
//  Created by ios on 16/9/22.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGZNXDetailViewController.h"
#import "BGFaBuZNXController.h"
#import "LTOVELabelEdgInsert.h"

@interface UILabel ()
@property (nonatomic, assign) UIEdgeInsets contentInsets;
@end

@interface BGZNXDetailViewController ()
@end

@implementation BGZNXDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"站内信详情";
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"回复" style:UIBarButtonItemStylePlain target:self action:@selector(reply)];
    right.title = @"回复";
    self.navigationItem.rightBarButtonItem = right;
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc] init];
    back.title = @"";
    self.navigationItem.backBarButtonItem = back;
    
    // Do any additional setup after loading the view.
    [self createUI];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)reply {
    
    BGFaBuZNXController *a = [[BGFaBuZNXController alloc] init];
    a.name = self.fromname;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:a animated:YES];
    
}
- (void)createUI {
    
    UIScrollView *s = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -64, BGWidth, screenH + 64)];
    s.bounces = NO;
    [self.view addSubview:s];
    
    UIView *xiushi = [[UIView alloc] initWithFrame:CGRectMake(21, 144, BGWidth - 42, 1)];
    xiushi.backgroundColor = dockwhite_;
    [s addSubview:xiushi];
    
    //标题啊
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(21, 84, 77, 21)];
    title.font = [UIFont systemFontOfSize:16];
    title.text = [NSString stringWithFormat:@"标题：%@",self.title1];
    CGSize labSize = [title.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:title.font,NSFontAttributeName, nil]];
    title.width = labSize.width;
    title.height = labSize.height;
    [s addSubview:title];
    
    //发件人
    UILabel *person = [[UILabel alloc] initWithFrame:CGRectMake(21, title.bottom + 10, 77, 16)];
    person.font = [UIFont systemFontOfSize:12];
    person.text = [NSString stringWithFormat:@"发件人:%@",self.fromname];
    person.textColor = dockGray_;
    CGSize personSize = [person.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:person.font,NSFontAttributeName, nil]];
    person.width = personSize.width;
    person.height = personSize.height;
    [s addSubview:person];
    
    //小时间
    UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(person.right + 30, title.bottom + 10, BGWidth - 21 - person.right + 50, 16)];
    time.font = [UIFont systemFontOfSize:12];
    NSDate *dat = [NSDate dateWithTimeIntervalSince1970:[self.add_time intValue]];
    NSDateFormatter *fat = [[NSDateFormatter alloc] init];
    [fat setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr = [fat stringFromDate:dat];
    time.text = [NSString stringWithFormat:@"时间：%@",timeStr];
    time.textColor = dockGray_;
    CGSize timeSize = [time.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:time.font,NSFontAttributeName, nil]];
    time.width = timeSize.width;
    time.height = timeSize.height;
    time.textAlignment = NSTextAlignmentRight;
    [s addSubview:time];
    
    //小详情
    UILabel *detail = [[UILabel alloc] initWithFrame:CGRectMake(21, xiushi.bottom + 10, BGWidth - 42, MAXFLOAT)];
    detail.text = [NSString stringWithFormat:@"详情：%@",self.cont];
    detail.font = [UIFont systemFontOfSize:16];
//    CGSize detailSize = [detail.text sizeWithAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:detail.font,NSFontAttributeName, nil]];
//    detail.width = detailSize.width;
//    detail.contentInsets = UIEdgeInsetsMake(30, 0, 0, 0);
//    if (detailSize.width > BGWidth - 42) {
//        detail.height = 21 * detailSize.width / BGWidth - 42 + 1;
//    }
//    detail.height = detailSize.height;
    detail.numberOfLines = 0;
//    detail.lineBreakMode = NSLineBreakByWordWrapping;
//    detail.textAlignment = NSTextAlignmentNatural;
    [detail sizeToFit];
    detail.y = xiushi.bottom + 10;
    [s addSubview:detail];
    
    s.contentSize = CGSizeMake(0, detail.bottom);
    
}

- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}

@end
